<?php

use app\common\enum\DeliveryType as DeliveryTypeEnum;

?>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf"><?= $title ?></div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom-xs am-cf">
                        <form id="form-search" class="toolbar-form" action="">
                            <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                            <input type="hidden" name="dataType" value="<?= $dataType ?>">
                            <div class="am-u-sm-12 am-u-md-3">
                                <div class="am-form-group">
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <?php if (checkPrivilege('merchant/export')): ?>
                                                <a class="j-export am-btn am-btn-success am-radius"
                                                   href="javascript:void(0);">
                                                    <i class="iconfont icon-daochu am-margin-right-xs"></i>订单导出
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-9">
                                <div class="am fr">
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="start_time" class="am-form-field"
                                               value="<?= $request->get('start_time') ?>" placeholder="请选择起始日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="end_time"
                                               class="am-form-field"
                                               value="<?= $request->get('end_time') ?>" placeholder="请选择截止日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="search"
                                                   placeholder="请输入订单号/用户昵称" value="<?= $request->get('order_no') ?>">
                                            <div class="am-input-group-btn">
                                                <button class="am-btn am-btn-default am-icon-search" type="submit"></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="order-list am-scrollable-horizontal am-u-sm-12 am-margin-top-xs">
                        <table width="100%" class="am-table am-table-centeredam-text-nowrap am-margin-bottom-xs">
                            <thead>
                                <tr>
                                    <th width="10%" class="goods-detail">商品信息</th>
                                    <th>单价/数量</th>
                                    <th width="8%">付款金额</th>
                                    <th>订单者</th>
                                    <th>使用时间</th>
                                    <th>失效时间</th>
                                    <th>订单状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $colspan = 8; ?>
                                <?php if ( !$list->isEmpty() ): foreach ($list as $order): ?>
                                    <tr class="order-empty">
                                        <td colspan="<?= $colspan ?>"></td>
                                    </tr>
                                    <tr>
                                        <td class="am-text-middle am-text-left" colspan="<?= $colspan ?>">
                                            <span class="am-margin-right-lg">订单生成时间:<?= date('Y-m-d H:i:s', $order['create_time'] )?></span>
                                            <span class="am-margin-right-lg">订单号：<?= $order['order_no'] ?></span>
                                            <span class="am-margin-right-lg">交易号：<?= $order['transaction_no'] ?></span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="goods-detail am-text-middle">
                                            <div class="goods-image">
                                                <img src="/uploads/<?= $order['file_name']?>" onerror="this.src='/uploads/202207030914418f3b18004.jpeg'" alt="">
                                            </div>
                                            <div class="goods-info">
                                                <p class="goods-title">门票名：<?= $order['name']?></p>
                                            </div>
                                        </td>
                                        <td class="am-text-middle">
                                            <p>￥<?= $order['article_price'] ?></p>
                                            <p>×<?= $order['num'] ?>(张)</p>
                                        </td>
                                        <td class="am-text-middle">
                                            <p>￥<?= $order['article_price'] ?></p>
                                        </td>
                                        <?php $goodsCount = 1; ?>
                                        <td class="am-text-middle" rowspan="<?= $goodsCount ?>">
                                            <p><?= $order['nickName'] ?></p>
                                            <p class="am-link-muted">(用户id：<?= $order['user_id'] ?>)</p>
                                        </td>
                                        <td class="am-text-middle" rowspan="<?= $goodsCount ?>">
                                            <p><?= date('Y-m-d H:i:s', $order['start_time'] )?></p>
                                        </td>
                                        <td class="am-text-middle" rowspan="<?= $goodsCount ?>">
                                            <p><?= date('Y-m-d H:i:s', $order['end_time'] )?></p>
                                        </td>
                                        <td class="am-text-middle" rowspan="<?= $goodsCount ?>">
                                            <p>订单状态：
                                                <span class="am-badge am-badge-warning">
                                                    <?php
                                                        if( $order['order_status'] == 200 ){
                                                            echo '已支付 待核销';
                                                        } else if( $order['order_status'] == 201 ){
                                                            echo '已取消';
                                                        } else if( $order['order_status'] == 300 ){
                                                            echo '已核销 待确认';
                                                        } else if( $order['order_status'] == 400 ){
                                                            echo '已确认 待评价';
                                                        } else if( $order['order_status'] == 500 ){
                                                            echo '已完成';
                                                        } else if( $order['order_status'] == 600 ){
                                                            echo '已评价 待完成';
                                                        } else if( $order['order_status'] == 800 ){
                                                            echo '已结束';
                                                        }
                                                    ?>
                                                </span>
                                            </p>
                                        </td>

                                        <td class="am-text-middle" rowspan="<?= $goodsCount ?>">
                                            <div class="tpl-table-black-operation">
                                                <?php if (checkPrivilege('merchant/detail')): ?>
                                                    <a class="tpl-table-black-operation-green"
                                                       href="<?= url('merchant/detail', ['id' => $order['id']]) ?>">订单详情</a>
                                                <?php endif; ?>
                                            </div>
                                        </td>

                                    </tr>
                                <?php endforeach; else: ?>
                                    <tr>
                                        <td colspan="<?= $colspan ?>" class="am-text-center">暂无记录</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?= $list->render() ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    $(function () {

        /**
         * 订单导出
         */
        $('.j-export').click(function () {
            var data = {};
            var formData = $('#form-search').serializeArray();
            $.each(formData, function () {
                this.name !== 's' && (data[this.name] = this.value);
            });
            window.location = "<?= url('merchant/export') ?>" + '&' + $.urlEncode(data);
        });

    });

</script>